<?php
 require("abifunktsioonid.php");
 session_start();
 if(isSet($_REQUEST["username"])){
 $kask=$yhendus->prepare("SELECT group_type, realname FROM users WHERE username=? AND password=PASSWORD(?)");
 $knimiparool=$_REQUEST["username"]."_".$_REQUEST["password"];
 $kask->bind_param("ss", $_REQUEST["username"], $knimiparool);
 $kask->bind_result($group_type, $realname);
 $kask->execute();
 if($kask->fetch()){
 $_SESSION["username"]=$_REQUEST["username"];
 $_SESSION["group_type"]=$group_type;
 $_SESSION["realname"]=$realname;
 $kask->close();
 }
 }
 if(isSet($_REQUEST["lahku"])){
 unset($_SESSION["username"]);
 }

?>
<!doctype html>
<html>
 <head>
 <meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="kujundus.css">
 <title>Bon Services OY</title>

 </head>
 <body>
<div id="main">
 <img id="header" src="bso.png" alt="logo" href="login.php"/>
</div><div id="main2"><div id="main3">



 <?php if(isSet($_SESSION["username"])): ?>

  <div id="sisu">
  
 

 
 
 
 
 <?php if($_SESSION["group_type"]=="0"):?>
 <p>Oled tööde tellija - <?php echo $_SESSION["realname"]; ?></p>
 <a href="customer.php">Redigeeri töölepinguid</a>
 <br/>
 <a href="customer_add.php">Lisa töölepinguid</a>
 <?php endif ?>

 <?php if($_SESSION["group_type"]=="1"):?>
 <p>Oled sisse loginud Töölisena</p>
 <a href="worker.php">Sisesta töötunde</a>

 


 <?php endif ?>

 <?php if($_SESSION["group_type"]=="2"): ?>
 <a href="manager.php" > Statistika leht </a>

 <?php endif ?>
 </div>
 <div style="margin-top:300px;" id="kasutaja">
	 
	  <p id="kasutajad"><?php echo $_SESSION["realname"]; ?>
 <a href="?lahku" id="lahku">lahku</a></p>
 </div>
 

 <?php else: ?>

 <div id="login">
 <form action="?" method="post" >
 <dl id="form">
 
 <dd style="float:right;margin-right:100px">Username: <input id="username" type="text" name="username" /></dd>
 <dd style="float:right;margin-right:100px">Password: <input id="password" type="password" name="password" /></dd>
 <dd><input id="button" type="submit" value="Sisene" /></dd>
 </dl>
 </form>
 <div>

 <?php endif ?>

 </div>
 </div>
 </div>
 </body>
</html>
<?php 
$yhendus->close();
?>
